<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>Title</title>
    <script src="<%=basePath%>/js/jquery.js"></script>
    <script src="<%=basePath%>/js/util/util.js"></script>
    <script>
       function ajax() {
            $.ajax({
                type:"POST",
                url : "<%=basePath%>user/getUser3.do",
                data : {
                    userName : "name"
                },
                success : function(meg) {
                    if(meg =="ok"){
                        window.location="<%=basePath%>user/main.do";
                    }else{
                        $(".myLable").text(meg);
                    }
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("网络错误");
                }
            });
        }
        function ajax2() {
            $.ajax({
                type:"POST",
                url : "<%=basePath%>user/getUser4.do",
                data : {
                    userName : "name"
                },
                success : function(meg) {
                    console.log(meg);
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("网络错误");
                }
            });
        }
        function ajax3() {
            $.ajax({
                type:"POST",
                url : "<%=basePath%>user/getUser5.do",
                data : {
                    userName : "name"
                },
                success : function(meg) {
                    alert(meg);
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("网络错误");
                }
            });
        }
        function ajax4() {
            $.ajax({
                type:"POST",
                url : "<%=basePath%>user/getUser6.do",
                data : {
                    userName : "name"
                },
                success : function(meg) {
                    alert(meg);
                },
                error:function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("网络错误");
                }
            });
        }
    </script>
</head>
<body>
main...
传参方式<br>
1.表单name 接受user对象接受
<form action="<%=basePath%>user/getUser1.do" method="post">
    名字<input type="text" name="userName" value="${name}">
    密码<input type="text" name="password" value="${pwd}">
    <button type="submit">查询</button>
</form>
2.表单name 接受一个一个属性接受
<form action="<%=basePath%>user/getUser2.do" method="post">
    名字<input type="text" name="userName" value="${name}">
    密码<input type="text" name="password" value="${pwd}">
    <button type="submit">查询</button>
</form>
3.ajax传值 response.getWriter()返回值为字符串
<button onclick="ajax()">ajax</button>
<label class="myLable"></label><br>

4.ajax传值 response.getWriter()返回值为list需要转json
<button onclick="ajax2()">ajax</button>
<label class="myLable"></label><br>

5.ajax传值 @ResponseBody String返回值为字符串 中文乱码  头上加produces = "application/json; charset=utf-8" 只解决单个问题
<button onclick="ajax3()">ajax</button>
<label class="myLable"></label><br>

6.ajax传值  @ResponseBody String返回值为list 不需要转json
<button onclick="ajax4()">ajax</button>
<label class="myLable"></label><br>
</body>
</html>
